package com.sfx.算法专题.前缀和;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 前缀和模板题
 * User: sfx
 * Date: 2023-08-12
 * Time: 22:35
 */
public class Code_1_PrefixSum {
    public void prefixSum() {
        Scanner scan = new Scanner(System.in);
        //读入两个整数n和q
        int n = scan.nextInt(), q = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; ++i) arr[i] = scan.nextInt();
        // 进行预处理前缀和
        long[] dp = new long[n + 1];
        for (int i = 1; i <= n; ++i) dp[i] = dp[i - 1] + arr[i - 1];
        // 进行q次询问
        for (int i = 0; i < q; ++i) {
            int l = scan.nextInt(), r = scan.nextInt();
            System.out.println(dp[r] - dp[l - 1]);
        }
    }
}